#include "YGRoot.h"
#include "YGGame.h"
//#include "YGEntryPoint.h"
#include "Android\YGRootAndroid.h"
//#include "YoghurtGum.h"

using namespace YoghurtGum;

class PureVirtualTest
{

public:

	PureVirtualTest() { }
	~PureVirtualTest() { }

	virtual bool PureVirtual() = 0;

};

class ObjectTest
{

public:

	ObjectTest() { }
	~ObjectTest() { }

	PureVirtualTest* m_Test;

};

class TestGame : public Game
{

public: 

	TestGame() : Game()
	{
		m_Color = 0.f;
	}
	~TestGame()
	{

	}

	void Init()
	{

	}
	void Update()
	{
		m_Color += 0.05f;
		if (m_Color > 1.f) { m_Color = 0.f; }
	}
	void Render()
	{
		m_Color += 0.05f;
		if (m_Color > 1.f) { m_Color = 0.f; }

		glClearColor(m_Color, 0.0f, 1.f - m_Color, 0.0f);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	}

	float m_Color;

};

Game* Game::Configure()
{
	return new TestGame;
}

#if 0

#include <jni.h>
#include <android/log.h>

#include <stdio.h>

#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>

static char print_msg[256];
#define DEBUG(msg, ...) { \
	sprintf(print_msg, msg, ##__VA_ARGS__); \
	__android_log_print(ANDROID_LOG_INFO, "YoghurtGum", print_msg); \
}

#define YG_JAVA_PACKAGE_PATH                      yg_engine
#define NATIVE_NAME1(javaclass, name, package)    Java_##package##_##javaclass##_##name
#define NATIVE_NAME2(javaclass, name, package)    NATIVE_NAME1(javaclass, name, package)
#define NATIVE_NAME(javaclass, name)	          NATIVE_NAME2(javaclass, name, YG_JAVA_PACKAGE_PATH)
#define NATIVE_PRE                                JNIEXPORT
#define NATIVE_FUNC(javaclass, name)              JNICALL NATIVE_NAME(javaclass, name) (JNIEnv* env, jobject thiz)
#define NATIVE_FUNC_ARGS(javaclass, name, args)   JNICALL NATIVE_NAME(javaclass, name) (JNIEnv* env, jobject thiz, args)

JNIEnv* g_JavaEnvironment;
jobject g_JavaObject;

bool CloseApp()
{
    DEBUG("CloseApp");
    
    jclass cls = g_JavaEnvironment->GetObjectClass(g_JavaObject);
    jmethodID mid = g_JavaEnvironment->GetMethodID(cls, "CloseApp", "()V");
    if (mid == 0)
    {
		DEBUG("Couldn't find function");
		return false;
    }
    g_JavaEnvironment->CallVoidMethod(g_JavaObject, mid);
    return true;
}

bool g_Startup = false;
float g_Color = 0.f;

#ifdef __cplusplus
extern "C" {
#endif

//JNIEXPORT void JNICALL Java_yg_game_Galaxians_YGRenderer_NativeInit(JNIEnv*, jobject)
NATIVE_PRE void NATIVE_FUNC(YGActivity, NativeInit)
{
	int argc = 0;
	char * argv[] = { "" };
	
	g_JavaEnvironment = env;
	g_JavaObject = thiz;

	DEBUG("Init.");
	
	g_Startup = true;
}

float value = 1.f;
NATIVE_PRE void NATIVE_FUNC(YGRenderer, NativeRender)
{
	//value += 0.1f;
	//value = (value > 1.f) ? 0.f : value;

	glClearColor(g_Color, 0.0f, 1.f - g_Color, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}

/* Call to finalize the graphics state */

NATIVE_PRE void NATIVE_FUNC(YGView, NativePause)
{
	DEBUG("Paused.");
}

NATIVE_PRE void NATIVE_FUNC_ARGS(YGActivity, NativeKeyPress, jint a_Key)
{
	DEBUG("Key pressed: %i", a_Key);
	if (a_Key == 62)
	{
	    CloseApp();
	}
	if (a_Key == 19) 
	{
	    g_Color += 0.1f;    
	    if (g_Color > 1.f) { g_Color = 1.f; }
	}
	if (a_Key == 20)
	{
	    g_Color -= 0.1f;
	    if (g_Color < 0.f) { g_Color = 0.f; }
	}
}

NATIVE_PRE void NATIVE_FUNC(YGActivity, NativeDone)
{
	DEBUG("Quit.");
}

NATIVE_PRE jint NATIVE_FUNC(YGActivity, NativeExit)
{
	DEBUG("Exiting? %s", (g_Startup) ? "YES" : "NO");
	if (g_Startup) { return 1; }
	return 0;
}

#ifdef __cplusplus
}
#endif

#endif